Array.prototype.myforEach = function (callback, thisValue) {
    // this=> arr
    let self = this;
    let length = this.length;
    for (let i = 0; i < length; i++) {
        typeof callback == 'function' && callback.call(self, self[i], i, self);
    }
}


Array.prototype.myfilter = function (callback, thisValue) {
    // this=> arr
    let self = this;
    let length = this.length;
    let newArr = []
    for (let i = 0; i < length; i++) {
        if (callback.call(self, self[i], i, self)) {
            newArr.push(self[i]);
        }
    }
    return newArr;
}
Array.prototype.mymap = function (callback, thisValue) {
    // this=> arr
    let self = this;
    let length = this.length;
    let newArr = []
    for (let i = 0; i < length; i++) {
        newArr.push(callback.call(self, self[i], i, self) + thisValue);
    }
    return newArr;
}

Array.prototype.myreduce = function (callback, thisValue) {
    for (var i = 0; i < this.length; i++) {
        if (!thisValue) {
            thisValue = callback(this[i], this[i + 1], i + 1, this);
            i++;
        } else {
            thisValue = callback(thisValue, this[i], i, this);
        }
    }
    return thisValue;
}

Array.prototype.myreduce1 = function (callback, thisValue) {

    // this=> arr
    let self = this;
    let length = this.length;
    let startindex = thisValue ? 0 : 1;
    let res = thisValue ? thisValue : numbers[0];
    for (let i = startindex; i < length; i++) {
        newArr.push(callback.call(self, self[i], i, self));
    }
    return thisValue;
}

Array.prototype.myfind = function (callback, thisValue) {
    for (var i = 0; i < this.length; i++) {
        if (callback(this[i], i, this)) {
            return this[i];
            // return i // findIndex
        }
    }
    return;
}

Array.prototype.myevery = function (callback, thisValue) {
    // this=> arr
    let self = this;
    let length = this.length;
    let flag = true;
    for (let i = 0; i < length; i++) {
        if (!callback.call(this, self[i], i, self)) {
            flag = false;
            break;
        }
    }
    return flag;
}


Array.prototype.mysome = function (callback, thisValue) {
    // this=> arr
    let self = this;
    let length = this.length;
    let flag = false;
    for (let i = 0; i < length; i++) {
        if (callback.call(this, self[i], i, self)) {
            flag = true;
            break;
        }
    }
    return flag;
}

Array.prototype.mysArray = function (obj) {
    return Object.prototype.toString.call(obj) === '[object Array]';
}
Array.prototype.myArrayOf = function () {
    return [].slice.call(arguments);
}

var numbers = [1, 2, 3, 4, 5];
// numbers.myforEach(function (value, index, arr) {
//     console.log(value + "---" + index + " ---" + arr);
// })

// var res = numbers.myfilter(function (value, index, arr) {
//     return value > 9;
// })

// var res = numbers.mymap(function (value, index, arr) {
//     return value * 9;
// }, 1)

// var res = numbers.myreduce(function (previousValue, currentValue, currentIndex, arr) {
//     return previousValue + currentValue;
// })
// console.log(res);

// console.log([].myArrayOf(3, 11, 8));// [3,11,8]
// console.log([].myArrayOf(3));// [3]
// console.log([].myArrayOf(3).length); // 1 

// var res = numbers.myfind(function (value, index, arr) {
//     return value > 30;
// })
var res = numbers.myevery(function (value, index, arr) {
    return value > 0;
})
console.log(res);


